package com.link2room.ironhide.controller.inside;


import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.common.util.StringUtil;
import com.link2room.ironhide.dto.param.base.RoomtypeBaseParamDto;
import com.link2room.ironhide.dto.result.base.L2RHotelRmtypePictureDto;
import com.link2room.ironhide.dto.result.base.L2RRoomtypeDto;
import com.link2room.ironhide.facade.IRoomtypeFacadeService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by sss on 2016/8/29.
 */
@Api(value = "/in/Roomtypes", description = "房型基础信息相关")
@RestController
@RequestMapping("/in/Roomtypes")
public class RoomtypeInsideController {
    @Resource
    private IRoomtypeFacadeService roomtypeFacadeService;

    @RequestMapping(method= RequestMethod.GET)
    public @ResponseBody BaseResultDto roomtypeList(
            @RequestParam(value = "lhotelCode" ,required = true) String lhotelCode,
            @RequestParam(value = "isHalt" ,required = false) String isHalt
    ) throws Exception {
        RoomtypeBaseParamDto roomtypeBaseParamDto =new RoomtypeBaseParamDto();
        roomtypeBaseParamDto.setLhotelCode(lhotelCode);
        roomtypeBaseParamDto.setIsHalt(isHalt);
        QueryResult<L2RRoomtypeDto> roomtypeResult = roomtypeFacadeService.listRoomType(roomtypeBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(roomtypeResult);
        return l2rRs;
    }

    @RequestMapping(value = "/Roomtype",method= RequestMethod.GET)
    public @ResponseBody BaseResultDto roomTypeDto(
            @RequestParam(value = "lhotelCode" ,required = true) String lhotelCode,
            @RequestParam(value = "rmtype" ,required = true) String rmtype
    ) throws Exception {
        RoomtypeBaseParamDto roomtypeBaseParamDto =new RoomtypeBaseParamDto();
        roomtypeBaseParamDto.setLhotelCode(lhotelCode);
        roomtypeBaseParamDto.setRmtype(rmtype);
        L2RRoomtypeDto roomtype = roomtypeFacadeService.getRoomtypeDto(roomtypeBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(roomtype);
        return l2rRs;
    }

    @RequestMapping(value = "/RoomtypeBigPics",method= RequestMethod.GET)
    public @ResponseBody BaseResultDto roomtypeBigPics(
            @RequestParam(value = "lhotelCode" ,required = true) String lhotelCode,
            @RequestParam(value = "rmtypes" ,required = false) String rmtypes,
            @RequestParam(value = "rmtype" ,required = false) String rmtype
    ) throws Exception {
        List<String> rmtypeList=new ArrayList();
        if(StringUtil.isNotBlank(rmtypes)){
            String[] rmtypeArr = rmtypes.split(",");
            for(String roomtype:rmtypeArr){
                rmtypeList.add(roomtype);
            }
        }
        if(StringUtil.isNotBlank(rmtype)){
            rmtypeList.add(rmtype);
        }
        RoomtypeBaseParamDto roomtypeBaseParamDto =new RoomtypeBaseParamDto();
        roomtypeBaseParamDto.setLhotelCode(lhotelCode);
        roomtypeBaseParamDto.setRmtypes(rmtypeList);
        QueryResult<L2RHotelRmtypePictureDto> hotelBigPicResult = roomtypeFacadeService.getRmtypeBigPic(roomtypeBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(hotelBigPicResult);
        return l2rRs;
    }

    @RequestMapping(value = "/RoomtypePics",method= RequestMethod.GET)
    public @ResponseBody BaseResultDto roomtypePics(
            @RequestParam(value = "lhotelCode" ,required = true) String lhotelCode,
            @RequestParam(value = "rmtypes" ,required = false) String rmtypes
    ) throws Exception {
        List<String> rmtypeList=new ArrayList();
        if(StringUtil.isNotBlank(rmtypes)){
            String[] rmtypeArr = rmtypes.split(",");
            for(String rmtype:rmtypeArr){
                rmtypeList.add(rmtype);
            }
        }
        RoomtypeBaseParamDto roomtypeBaseParamDto =new RoomtypeBaseParamDto();
        roomtypeBaseParamDto.setLhotelCode(lhotelCode);
        roomtypeBaseParamDto.setRmtypes(rmtypeList);
        QueryResult<L2RHotelRmtypePictureDto> hotelBigPicResult = roomtypeFacadeService.getRmtypePics(roomtypeBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(hotelBigPicResult);
        return l2rRs;
    }
}
